package com.jingxi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jingxi.common.pojo.EasyUIDataGridResult;
import com.jingxi.common.pojo.JingXiResult;
import com.jingxi.model.TbItem;
import com.jingxi.service.ItemService;

@Controller
public class ItemController {
	
	@Autowired
	private ItemService itemService;
	
	@RequestMapping("/item/{id}")
	@ResponseBody
	public TbItem getTbItemById(@PathVariable long id) {
		TbItem tbItem = itemService.getTnItemById(id);
		return tbItem;
	}
	
	@RequestMapping("/item/list")
	@ResponseBody
	public EasyUIDataGridResult getItemList(Integer page, Integer rows) {
		System.out.println(page + " -- " + rows);
		EasyUIDataGridResult result = itemService.getItemList(page, rows);
		return result;
	}
	
	@RequestMapping("/item/save")
	@ResponseBody
	public JingXiResult createItem(TbItem tbItem,String desc,String itemParams) {
		System.out.println("TbItem" + tbItem.getTitle() + "Desc" + desc);
		JingXiResult result = itemService.createItem(tbItem,desc,itemParams);
		return result;
	}

	@RequestMapping("/rest/item/query/item/desc/{id}")
	@ResponseBody
	public JingXiResult getItem(@PathVariable long id) {
		return itemService.getDescFromId(id);
		
	}
	
	@RequestMapping("/rest/item/update")
	@ResponseBody
	public JingXiResult updateItem(TbItem tbItem,String desc) {
		return itemService.updateItem(tbItem,desc);
	}
	
	@RequestMapping("/rest/item/delete")
	@ResponseBody
	public JingXiResult deleteItem(long[] ids) {
		return itemService.deleteItem(ids);
	}
}
